<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head  th:include="head::htmlhead">
</head>
<body>
<form id="addMessage" class="layerSelfWrap" style="">
    <div class="layui-form layuimini-form">
        <div class="layui-form-item">
            <label class="layui-form-label required">留言者</label>
            <div class="layui-input-block">
                <input type="text" name="author" lay-verify="required" lay-reqtext="留言人不能为空" placeholder="请输入留言"  class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label ">留言对象</label>
            <div class="layui-input-block">
                <input type="text" name="reader"  placeholder="请输入留言对象" value="" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">留言</label>
            <div class="layui-input-block">
                <textarea name="message" class="layui-textarea" placeholder="请输入留言(建议50字以内，其余加到备注)"></textarea>
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">备注</label>
            <div class="layui-input-block">
                <textarea name="remark" class="layui-textarea" placeholder="请输入备注信息"></textarea>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="saveMessage">确认</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </div>
</form>
<script src="lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script>
    layui.use('form', function () {
        var form = layui.form, layer = layui.layer, $ = layui.jquery;
        //监听提交
        form.on('submit(saveMessage)', function (data) {
            /*layer.msg(JSON.stringify(data.field));
            return false;*/
            $.ajax({
                url: "saveMessage",
                data: data.field,
                //dataType: 'JSON',
                type: 'POST',
                success: function (data) {
                    console.log("添加成功");
                    layer.confirm(data.msg,  {
                        icon: 1,
                        time: 2000 //2秒关闭（如果不配置，默认是3秒）
                    },  function () {
                        //layer.closeAll();
                        parent.layer.close(parent.layer.index);
                    });
                    /*layer.alert(data.msg, {
                        closeBtn: 0, btn: ['确认'], no: function () {
                            layer.closeAll();
                        }
                    });*/
                }
            });
            return false;
        });
    });
</script>
</body>
</html>
